import torch
from IPython.display import Image, display
from sklearn.model_selection import train_test_split
import numpy as np
import time
dataset_true = torch.load('datapoints_from_COSMOS2_real.pth')
dataset_false = torch.load('datapoints_from_COSMOS2_fake.pth')
dataset_true = np.array(dataset_true)
dataset_false = np.array(dataset_false)
train_indexes, test_indexes = train_test_split(np.arange(len(dataset_true)), test_size=3000, random_state=239)
train_indexes, val_indexes = train_test_split(train_indexes, test_size=3000, random_state=239)
train_data_fake = dataset_false[train_indexes]
val_data_fake = dataset_false[val_indexes]
test_data_fake = dataset_false[test_indexes]
train_data_true = dataset_true[train_indexes]
val_data_true = dataset_true[val_indexes]
test_data_true = dataset_true[test_indexes]
(res_corr, res_fake) = torch.load('val_saved_results_im_c1_c2_paired.pth')
print('Correct accuracy: ', np.mean([1 if val<0. else 0 for _, val in res_corr]))
Correct accuracy: 0.8266666666666667
print('Fake accuracy: ', np.mean([0 if val<0. else 1 for _, val in res_fake]))
Fake accuracy: 0.8306666666666667
res_corr.sort(key=lambda x: -x[1])
res_fake.sort(key=lambda x: x[1])
for point in res_corr[:20]:
index = point[0].item()
print('Predicted logit is: ', point[1])
dp = val_data_true[index]
print('Caption 1: ', dp['caption 1'])
print('Caption 2: ', dp['caption 2'])
display(Image(dp['img_local_path']))
print('='*100)
time.sleep(1)
Predicted logit is: 25.48 Caption 1: 18 photos of empty public spaces worldwide amidst COVID-19 outbreak Caption 2: Breaking news | The world is shaking coronavirus exploded
==================================================================================================== Predicted logit is: 25.22 Caption 1: Members of a Black militia group called the NFAC hold an armed rally at Parc Sans Souci in Lafayette, Louisiana, October 3. Caption 2: John ‘Grandmaster Jay’ Johnson, the group's leader, is seen kneeling in the street at Parc Sans Souci in Lafayette on Saturday
==================================================================================================== Predicted logit is: 23.66 Caption 1: Chicago Blackhawks center Jonathan Toews (19) reacts after scoring a goal against the Anaheim Ducks during the first period in Game 7 of the Western Conference final of the NHL hockey Stanley Cup playoffs in Anaheim, Calif., May 30, 2015. ( Caption 2: Sophomore forward Eddie Lang (7) battles for a loose puck in the offensive zone during the Rocky Mountain Center Ice Showdown, Oct. 19, 2013 at the Pepsi Center in Denver. (
==================================================================================================== Predicted logit is: 23.53 Caption 1: Brazil, revolt in the penitentiary: a carnage Caption 2: Brazil, Jair Bolsonaro is the new president
==================================================================================================== Predicted logit is: 23.25 Caption 1: Barney Pressman, right, in 1979, founded Barneys, and future generations of his family, including his son Fred and grandson Gene, helped run it for decades. Caption 2: Mr. Pressman with his son Fred and grandson Gene in 1979.
==================================================================================================== Predicted logit is: 21.67 Caption 1: Separating Families on Board Increases Safety Caption 2: Separating Families On The Plane Creates A Safety Risk!
==================================================================================================== Predicted logit is: 21.17 Caption 1: Protesters in Los Angeles on Saturday. Caption 2: Protesters sat in the middle of Beverly Boulevard in the Fairfax district of Los Angeles on Saturday.
==================================================================================================== Predicted logit is: 20.22 Caption 1: 24h through photos: Filipinos move house after typhoon Goni - Photo 7. Caption 2: Banda Aceh, Indonesia Cats lay on fishing nets. Indonesia is to boost funding to its maritime and fisheries sector to help the national economic recovery amid the coronavirus pandemic
==================================================================================================== Predicted logit is: 19.84 Caption 1: Firefighters examine debris left by protesters at the campus of the Polytechnic University in Hong Kong, on Nov 28, 2019. Caption 2: Firefighters examine debris left by protesters at the campus of the Polytechnic University (PolyU) in Hong Kong, November 28, 2019. Chow Yat-ming, a senior police officer said on Thursday night that the police would be able to finish their investigations by Friday. All officers would leave the site thereafter, enabling people to freely enter and exit the campus.
==================================================================================================== Predicted logit is: 19.55 Caption 1: Beverly Pepper, photographed in her studio in Todi, Italy. Caption 2: American sculptor Beverly Pepper, photographed in her studio in Todi, Italy. Excellent article: "Woman of Steel" by Megan O'Grady. Land Art, Ny Times, Art Studios, Alter, Female Art, Art History, Modern Art, Italy, Steel
==================================================================================================== Predicted logit is: 19.38 Caption 1: Istanbul, Erbinur Turson (right) in her small shop, taken this month Caption 2: Kalbinur Tursun, right, at her tailor shop in Istanbul this month.
==================================================================================================== Predicted logit is: 18.16 Caption 1: The Senate subcommittee report said eight federal departments, including the Department of Homeland Security, have regularly failed to fix cybersecurity vulnerabilities flagged by inspectors general reports. Caption 2: FEMA's ability to train new hires, or retrain existing staff for new roles, has been hindered by the coronavirus, officials said.
==================================================================================================== Predicted logit is: 17.94 Caption 1: Five Choices for the Detroit Tigers Next Pitching Coach Caption 2: The Michigan pitching coach Chris Fetter, right, said the Wolverines had the same technology as the Los Angeles Dodgers.
==================================================================================================== Predicted logit is: 17.39 Caption 1: Dancers Claudiu, Harry, Reece, Samantha and Claudine are seen backstage Caption 2: The performances at the Moulin Rouge still hold true to the traditions established at the cabaret's founding on October 6, 1889
==================================================================================================== Predicted logit is: 17.33 Caption 1: In the space there are screens to interact with the stories of the survivors. Caption 2: Immersive touch screens allow visitors to interact with survivors and hear their stories.
==================================================================================================== Predicted logit is: 16.97 Caption 1: Interpol Issues Red Notice For Owner And Captain Of Ship That Brought Ammonium Nitrate To Beirut Caption 2: Interpol issues notices over Lebanon’s massive port blast
==================================================================================================== Predicted logit is: 16.72 Caption 1: Harmony Dispensary, which sells marijuana for medical purposes, has seen more business since the spread of the coronavirus. Caption 2: Shaya Brodchandel, chief executive of Harmony Dispensary, examining marijuana plants in Secaucus, N.J. The company recently began providing medical marijuana to the state.
==================================================================================================== Predicted logit is: 16.47 Caption 1: Kidnapped entrepreneur Atre was fatally shot; death ruled homicide Caption 2: Santa Cruz County man’s kidnapping, death tied to robbery
==================================================================================================== Predicted logit is: 16.27 Caption 1: Brazil, Jair Bolsonaro is the new president Caption 2: Brazil, revolt in the penitentiary: a carnage
==================================================================================================== Predicted logit is: 15.33 Caption 1: A memorial for Kalief Browder, whose suicide after detention on Rikers Island spurred an overhaul. Caption 2: A memorial for Kalief Browder in New York in 2015. Since his death, the movement to abolish cash bail has grown stronger.
====================================================================================================
for point in res_fake[:20]:
index = point[0].item()
print(index)
print('Predicted logit is: ', point[1])
dp = val_data_fake[index]
print('Caption 1: ', dp['caption 1'])
print('Caption 2: ', dp['caption 2'])
display(Image(dp['img_local_path']))
print('='*100)
time.sleep(1)
1665 Predicted logit is: -34.25 Caption 1: This child is 11 years old and is taking our organic chemistry class. He said that if we have any questions, we can write to him and ask him Caption 2: Questions from a 9 year old in Chicago who hosts "The Show about Science."
==================================================================================================== 1738 Predicted logit is: -30.64 Caption 1: Outside the CNN offices at Columbus Circle in Manhattan on Wednesday after a bomb was found. Pipe bombs were also sent to Barack Obama and Hillary Clinton. No one was injured. Caption 2: Explosive devices were sent this week to CNN, at the Time Warner Center in Manhattan, as well as to prominent Democrats and critics of the president.
==================================================================================================== 1218 Predicted logit is: -29.6 Caption 1: View of Sagamore Hill from the south end Caption 2: Sagamore Hill, Theodore Roosevelt's family home, sits on 83 acres on Long Island. After a three-and-a-half-year restoration, the house reopens on Sunday.
==================================================================================================== 1305 Predicted logit is: -28.02 Caption 1: FARGO — “Happy” – Year 4, Episode 10 (Airs November 22) Pictured: E’myri Crutchfield as Ethelrida Pearl Smutny. CR: FX Caption 2: 'Fargo,' FX, second episode, "Full Moon," Eden Ahbez, "where all things are crowned with love and bound with love"
==================================================================================================== 2619 Predicted logit is: -26.72 Caption 1: On Tuesday, several residents of the Courtyard Apartments held a protest at the site of the well. Caption 2: City Developers Play Down Stapleton Name
==================================================================================================== 1554 Predicted logit is: -25.28 Caption 1: The scene of the NSTB discussion conference, the picture comes from the Internet, and the copyright belongs to the author Caption 2: Europe is full of contradictions when it comes to China: Afraid of Beijing's influence, but loves money
==================================================================================================== 2188 Predicted logit is: -25.06 Caption 1: Ms. Takato drying her daughter's hair after her nightly bath. Caption 2: Kazuko Yoshida doing the family's laundry after dinner.
==================================================================================================== 2346 Predicted logit is: -23.22 Caption 1: Immigration’s own song praises Canada, this video is on Caption 2: Tony Turner, a scientist in habitat planning at Environment Canada, was sent home on leave with pay pending a government investigation into the making of Harperman, a YouTube folk song critical of Conservative Leader Stephen Harper.
==================================================================================================== 1592 Predicted logit is: -22.64 Caption 1: A large crevasse forms near the calving front of the Helheim glacier near Tasiilaq, Greenland, June 22, 2018. Caption 2: Subtle detail in the Larsen C Ice Shelf. The large crack in the upper right is the beginning of the formation of Iceberg A-68. North is to the left.
==================================================================================================== 1413 Predicted logit is: -21.06 Caption 1: Serbian fans clash with riot police at last year's match Caption 2: Fans of Serbia roll a barrel towards the riot police during clashes at the Euro 2016 Group I qualifying soccer match between Serbia and Albania at the FK Partizan stadium in Belgrade October 14, 2014.
==================================================================================================== 2504 Predicted logit is: -20.88 Caption 1: A suspected gunman walks outside the premises of the Chhatrapati Shivaji Terminus or Victoria Terminus railway station in Mumbai, November 26, 2008. Caption 2: 2/7Closed circuit television footage released on 3 December 2008 shows terrorists walking across a parking lot after the shooting spree at the Chhatrapati Shivaji Terminus train station in Mumbai on 26 November
==================================================================================================== 2666 Predicted logit is: -20.42 Caption 1: Ukrainian Armed Forces / Zbroyni Syly Ukrayiny - Page 9 HWhoCqSLxoo Caption 2: OPEN LESSON IN RUSSIAN LANGUAGE on the topic: "Which members of the sentence are homogeneous" - grade 8
==================================================================================================== 2227 Predicted logit is: -19.97 Caption 1: The story of the veterans who witnessed secret atomic testing and how their decades-long struggle for recognition affects soldiers today. Caption 2: war ii 70 years later: How World War II changed America
==================================================================================================== 2470 Predicted logit is: -19.86 Caption 1: A self-portrait of the artist as a young woman. Caption 2: What happens on Page 76 in four of this season’s books, as envisioned by the artist Sam McKinniss. Candle Drawing, T Magazine, Magazine Covers, Molly Ringwald, Book Of Poems, American Poets, Character Design Inspiration, Fashion Inspiration, Book Publishing
==================================================================================================== 1410 Predicted logit is: -19.73 Caption 1: Stock photo of Pope Francis visits Mozambique, Maputo, Mo?mbique - 04 Sep 2019 Caption 2: Pope Francis arriving to celebrate Mass in Zimpeto Stadium in Maputo, Mozambique, on Friday.
==================================================================================================== 2724 Predicted logit is: -19.16 Caption 1: Thirst turns to anger as Australia’s mighty river runs dry Caption 2: Salt pans and dams are scattered across drought-affected farmland in Western Australia, November 12, 2015.
==================================================================================================== 1656 Predicted logit is: -18.66 Caption 1: Super Blue Blood Moon Seen From Photograph by Paul Kane Caption 2: The moon casts a reddish hue over Lake Pend Oreille during a lunar eclipse in Idaho (2011)
==================================================================================================== 574 Predicted logit is: -18.25 Caption 1: "Little Monsters": Dave (Alexander England), a washed-up musician, volunteers to chaperone his nephew's kindergarten field trip after taking a shine to the plucky schoolteacher, Miss Caroline (Lupita Nyong'o). Dave's intentions are complicated by the presence of world-famous child entertainer and competitor for Miss Caroline's affections, Teddy McGiggle (Josh Gad). (Hulu) Caption 2: According to Maggie Gyllenhaal, "The Kindergarten Teacher" "wouldn't really work unless what was coming out" of 5-year-old Jimmy "was really compelling."
==================================================================================================== 791 Predicted logit is: -17.98 Caption 1: On the anniversary of 9/11, a military family based in Qatar honors those who lost their lives in the terrorist attacks. Caption 2: 9/11 anniversary: Relatives of victims of the attack on the Pentagon
==================================================================================================== 2161 Predicted logit is: -17.31 Caption 1: Mother Teresa,Mother Teresa canonization,Mother Teresa news, Mother Teresa latest news, Mother Teresa canonization news Caption 2: Nuns from the Missionaries of Charity in Kolkata, India, watch a live broadcast of the canonisation of Mother Teresa
====================================================================================================